﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;

public partial class SearchKhHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static List<string> GetAutoCompleteDataName(string prefix)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT DoiTacID,DoiTacName FROM dmdoitac WHERE " +
    "DoiTacName like @SearchText + '%' AND Kh_yn=1";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(string.Format("{0}-{1}", sdr["DoiTacName"], sdr["DoiTacID"]));
                }
            }
            //conn.Close();
        }
        return result;
    }

    [WebMethod]
    public static List<string> GetAutoCompleteDataValue(string prefix)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT DoiTacID,DoiTacName FROM dmdoitac WHERE " +
    "DoiTacID like @SearchText + '%'  AND Kh_yn=1";

            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(string.Format("{0}-{1}", sdr["DoiTacID"], sdr["DoiTacName"]));
                }
            }
            //conn.Close();
        }
        return result;
    }

}
